package com.example.map.myapplication.fragments;

import android.app.Activity;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.TextView;

import com.example.map.myapplication.R;
import com.example.map.myapplication.TestAct;

/**
 * Created by qundui on 2017/5/25.
 */

public class B extends Fragment {
    private View view;
    private TestAct mact;
    private TextView tv;
    public TextView getTv() {
        return tv;
    }
    @Nullable
    @Override
    public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        view = LayoutInflater.from(getActivity()).inflate(R.layout.b, container, false);
        initviews(view);
        return view;
    }

    @Override
    public void onAttach(Activity activity) {
        mact= (TestAct) activity;
        super.onAttach(activity);
    }

    private void initviews(View view) {
        tv= (TextView) view.findViewById(R.id.tv);
//     tv.setText(getArguments().getString("b"));
//        tv.setText(getArguments().getString("x"));
        Button btn= (Button) view.findViewById(R.id.btn);
        Button btn2= (Button) view.findViewById(R.id.btn2);
        btn2.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                A fragmentById = (A)mact.getSupportFragmentManager().findFragmentById(R.id.f1);
//                Bundle bundle=new Bundle();
//                bundle.putString("a","b frament 传给 a frament");
//                fragmentById.setArguments(bundle);
              fragmentById.getTv().setText("B frament 传给 A fragment");

            }
        });
        btn.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                TestAct activity = (TestAct) getActivity();
                activity.getTv().setText("I form Frament2");
            }
        });
    }


}

